<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :url="$api.article_getlist"
               :editData="editData"
               :new_url="this.$api.article_insert"
               :detail_url="this.$api.article_info"
               :edit_url="this.$api.article_save"
               label-width="100px"
               :is_default_edit="true"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "title",
          label: "文章标题",
          value: "",
          type: "input",
        },
        {
          name: "article_type_title",
          label: "文章分类标题",
          value: "",
          type: "input",
        },
        {
          name: "nick_name",
          label: "用户昵称",
          value: "",
          type: "input",
        },
        {
          name: "article_tid",
          label: "文章类型",
          value: '',
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '正常',
              value: 0
            },
            {
              label: '定制',
              value: 1
            },

            {
              label: '用户',
              value: 2
            }
          ]
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '显示',
              value: 1
            },
            {
              label: '隐藏',
              value: 0
            }
          ]
        },
      ],
      columnData: [
        {
          prop: "article_id",
          label: "id"
        },
        {
          prop: "title",
          label: "文章标题"
        },
        {
          prop: "article_tid",
          label: "文章类型"
        },
        {
          prop: "article_type_title",
          label: "文章分类标题"
        },
        {
          prop: "img_url",
          label: "轮播图",
          custom: true,
          type: 'image',
          width: '360px',
          height: '120px'
        },
        {
          prop: "display",
          label: "是否显示",
          custom: true,
          type: 'switch',
          url: this.$api.article_status
        },
        {
          prop: "sort",
          label: "排序",
          custom: true,
          type: 'input',
          url: this.$api.article_sort
        },
        {
          prop: 'btn_group',
          label: '操作',
          custom: true,
          type: 'btn_group',
          width: '200px',
          group: [
            {
              name: '编辑',
              type: 'edit',
              color: 'primary',
              detail_mark: 'article_id',
            },
            {
              name: '删除',
              type: 'delete',
              color: 'danger',
              url: this.$api.article_status
            }
          ]
        }
      ],
      editData: [
        {
          name: 'article_id',
          label: '文章id',
          value: '',
          type: 'input',
          display: 'none'
        },
        {
          name: 'title',
          label: '文章标题',
          value: '',
          type: 'input',
          rules: [
            { required: true, message: "请输入文章标题", trigger: "blur" },
          ]
        },
        {
          name: 'article_type',
          label: '文章分类',
          value: '',
          type: 'select',
          groups: [],
          rules: [
            { required: true, message: "请选择文章分类", trigger: "blur" },
          ]
        },
        {
          name: 'content',
          label: '文章内容',
          value: '',
          type: 'editor',
          width:'100%',
          // rules: [
          //   { required: true, message: "请输入文章内容", trigger: "blur" },
          // ]
        },
        {
          name: 'sort',
          label: '排序',
          value: '',
          type: 'input',
        },
        {
          name: 'display',
          label: '是否显示',
          value: '',
          type: 'switch',
          config: {
            'active_value': '1',
            'inactive-value': '0'
          }
        },
        {
          name: 'img_url',
          label: '文章封面图',
          value: '',
          type: 'image_upload',
          width: '100%',
          config: {
            accept: ".jpg,.png,.bmp,.gif,.svg",
            fileList: [],
            // is_icon:true
          }
        },
      ],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.getType();
  },
  methods: {
    getType () {
      this.$req.get(this.$api.article_type_getnopagelist).then(res => {
        let data = res.data;
        for (var i in data) {
          this.editData[2].groups.push({
            label: data[i].title,
            value: data[i].article_type_id,
          })
        }
      })
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>